package com.creator.paas.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;
import java.io.File;

@Configuration
@ConfigurationProperties(prefix = "paas")
public class StorageConfig {
    @Value("${invoice.upload.dir}")
    private String uploadDir;

    @Value("${invoice.thumbnail.dir}")
    private String thumbnailDir;


    @PostConstruct
    public void init() {
        // 确保上传目录存在
        File uploadDirectory = new File(uploadDir);
        if (!uploadDirectory.exists()) {
            uploadDirectory.mkdirs();
        }

        // 确保缩略图目录存在
        File thumbnailDirectory = new File(thumbnailDir);
        if (!thumbnailDirectory.exists()) {
            thumbnailDirectory.mkdirs();
        }
    }

    public String getUploadDir() {
        return uploadDir;
    }

    public String getThumbnailDir() {
        return thumbnailDir;
    }
}
